﻿using System;
using System.Web;
using System.Configuration;

namespace DaCredito
{

    public class WebSettings : GenericSettings
    {

        private ApplicationSettings ioApplication;

        public WebSettings()
            : base((PropertyList)HttpContext.Current.GetSection("setup"))
        {
        }

        public new static WebSettings Global
        {
            get
            {
                if (GenericSettings.Global == null)
                    GenericSettings.Global = new WebSettings();
                return (WebSettings)GenericSettings.Global;
            }
            set { GenericSettings.Global = value; }
        }

        /// <summary>
        /// Retorna as propriedades gerais relativas a uma aplicação baseada na TFC.Web.
        /// </summary>
        public ApplicationSettings Application
        {
            get { return this.ioApplication; }
        }

        protected override void InitSettings()
        {
            this.ioApplication = new ApplicationSettings(this);
        }

        #region ApplicationSettings

        /// <summary>
        /// Define as propriedades gerais relativas a uma aplicação baseada na TFC.NET.
        /// </summary>
        public class ApplicationSettings
        {
            /// <summary> 
            /// Objeto Settings.
            /// </summary>
            protected readonly WebSettings ioOwner;

            /// <summary>
            /// Construtor.
            /// </summary>
            protected internal ApplicationSettings(WebSettings aoOwner)
            {
                this.ioOwner = aoOwner;
            }

            /// <summary>
            /// Retorna a URL da página Home.
            /// </summary>
            public string HomeUrl
            {
                get { return this.ioOwner.Items.AsString["Application.HomeUrl"]; }
            }

            /// <summary>
            /// Retorna a URL da página Forbidden.
            /// </summary>
            public string ForbiddenUrl
            {
                get { return this.ioOwner.Items.AsString["Application.ForbiddenUrl"]; }
            }

        } // ApplicationSettings

        #endregion // ApplicationSettings

    } // WebSettings

} // Trends.TFC.Web
